import axios from "axios";

export default {
  get: ({ curPage, eachPage }) =>
    axios.get("/api/order", {
      params: {
        curPage, eachPage
      }
    })
      .then(({ data }) => data),

  // 新增订单
  addOrder: ({ commodities, isAffirmReceive, isPaySuccess, orderTime, totalPrice, userId, shoppingCartId, searchName, isDisplay }) =>
    axios({
      method: "post",
      url: "/api/order/addOrder",
      data: {
        commodities,
        isAffirmReceive,
        isPaySuccess,
        orderTime,
        totalPrice,
        userId,
        shoppingCartId,
        searchName,
        isDisplay
      }
    })
      .then(({ data }) => data),

  // 删除订单
  delOrder: (_id) =>
    axios({
      method: "delete",
      url: "/api/order/delOrder",
      data: {
        _id
      }
    })
      .then(({ data }) => data),

  // 通过商品和id名称查询订单
  findOrder: (data) =>
    axios.get("/api/order/findOrder", {
      params: data //params不使用大括号，使层次结构简单明了，原因：不可以使用双重对象传输，否则接口服务器只能解构外层对象，
    })
      .then(({ data }) => data),




  // 确认商品收货
  changeState: (_id) =>
    axios({
      method: "patch",
      url: "/api/order/changeState",
      data: {
        _id
      }
    })
      .then(({ data }) => data),
}